package com.yoosora.common.mode.request;

import com.yoosora.common.mode.ToString;

/**
 * @author yoosora
 */
public class BasicPageRequest extends ToString {
	private static final long serialVersionUID = -1070417294187584880L;
	protected int page = 1;
	protected int rows = 20;

	public int mysqlOffset() {
		return this.page > 1 ? (this.page - 1) * this.rows : 0;
	}

	public BasicPageRequest() {
	}

	public int getPage() {
		return this.page;
	}

	public int getRows() {
		return this.rows;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public void setRows(int rows) {
		this.rows = rows;
	}

	@Override
	public String toString() {
		return "BasicPageRequest(page=" + this.getPage() + ", rows=" + this.getRows() + ")";
	}

	@Override
	public boolean equals(Object o) {
		if (o == this) {
			return true;
		} else if (!(o instanceof BasicPageRequest)) {
			return false;
		} else {
			BasicPageRequest other = (BasicPageRequest)o;
			if (!other.canEqual(this)) {
				return false;
			} else if (this.getPage() != other.getPage()) {
				return false;
			} else {
				return this.getRows() == other.getRows();
			}
		}
	}

	protected boolean canEqual(Object other) {
		return other instanceof BasicPageRequest;
	}

	@Override
	public int hashCode() {
		int result = 1;
		result = result * 59 + this.getPage();
		result = result * 59 + this.getRows();
		return result;
	}
}
